<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Requests\Api\DailyRecord\StoreRequest;
use App\Requests\Api\School\ListRequest;
use App\Service\CommonService;
use App\Service\SchoolService;
use Illuminate\Http\Request;

class SchoolController extends Controller
{
    protected $schoolService;

    public function __construct(
        SchoolService $schoolService
    ){
        $this->schoolService = $schoolService;
    }

    /******************** 机构端 *************************/

    /**
     * 校区列表
     * @param StoreRequest $request
     * @return false|string
     * @throws \App\Exceptions\CustomException
     */
    public function agencyList(Request $request){
        CommonService::reqLog($request);
        try{
            $schoolInfo = $this->schoolService->list();
        }catch (\Exception $exception){
            customError($exception->getMessage(),$exception->getCode());
        }
        return responseData($schoolInfo['data'] ?? []);
    }



    public function getSkuOption(array $selectedValue){
        $skuList = array();
        $skuIndex = array();
        $notSelectedValue = array();
        //如果选中的规格个数等于当前商品所有规格个数则返回skuIndex，否则返回剩下需要高亮的规格值
        if (count($selectedValue) == $skuList['optionList']){
            foreach ($skuList['skuIndex'] as $skuKey => $skuValue){
                if (count(array_intersect($skuValue,$selectedValue)) == count($selectedValue)){
                    return $skuKey;
                }
            }
            return '规格值错误';
        }
        //获取所有skuIndex
        foreach ($selectedValue as $value){
            if (!in_array($skuList['opIndex'][$value],$skuIndex)){
                $skuIndex[] = $skuList['opIndex'][$value];
            }
        }
        //获取除了当前选中属性值之外的所有属性值
        foreach ($skuIndex as $value){
            $tempSkuValue = $skuList['skuIndex'][$value];
            foreach ($tempSkuValue as $tempValue){
                if (!in_array($tempValue,$selectedValue)){
                    $notSelectedValue[] = $tempValue;
                }
            }
        }
        return $notSelectedValue;
    }
}
